package com.edu.cq02.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 实现了HandlerInterceptor接口的自定义拦截器
 */
public class MyInterceptor implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) {
        System.out.println("preHandle在控制器方法调用前执行");
        System.out.println("拦截器拦截到了请求，请求的URI为：" + request.getRequestURI());

        //对拦截的请求进行放行处理
        return true;
    }
    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) {
        System.out.println("postHandle在控制器方法调用之后且视图解析之前执行");

    }
    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler,
                                Exception ex) {
        System.out.println("afterCompletion在整个请求完成后执行，即视图渲染结束之后执行");

    }

}

